package com.windward.vii.dao.mapper;

import com.windward.vii.dao.entity.Statistics;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface StatisticsMapper {
    @Delete({
        "delete from statistics",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int deleteByPrimaryKey(Long id);

    @Insert({
        "insert into statistics (id, url, ",
        "count)",
        "values (#{id,jdbcType=BIGINT}, #{url,jdbcType=VARCHAR}, ",
        "#{count,jdbcType=BIGINT})"
    })
    int insert(Statistics record);

    int insertSelective(Statistics record);

    @Select({
        "select",
        "id, url, count",
        "from statistics",
        "where id = #{id,jdbcType=BIGINT}"
    })
    @ResultMap("BaseResultMap")
    Statistics selectByPrimaryKey(Long id);

    int updateByPrimaryKeySelective(Statistics record);

    @Update({
        "update statistics",
        "set url = #{url,jdbcType=VARCHAR},",
          "count = #{count,jdbcType=BIGINT}",
        "where id = #{id,jdbcType=BIGINT}"
    })
    int updateByPrimaryKey(Statistics record);

    @Update({
            "update statistics",
            "set count = count + 1",
            "where url = #{url,jdbcType=VARCHAR}"
    })
    int increaseCountByUrl(String url);
}